const knex = require('knex')({
    client: 'mysql',
    connection: {
        host: '47.107.127.110',
        user: 'root',
        password: 'P)TNqEy:A7rC22T',
        database: 'yll_app',
        port: 3306,
    },
    // debug: true,
    // log: {
    //     warn(message) {},
    //     error(message) {},
    //     deprecate(message) {},
    //     debug(message) {

    //         const sql = knex.raw(message.sql, message.bindings).toString()
 
    //         message.sql = sql;

    //         console.log(message);
    //     },
    // }
})

const Moss = require('../');
const moss = new Moss(knex, {
    // 表前缀
    tablePrefix: 'yll_app'
});

(async () => {
    try {
        let data;

        data = await moss.create({
            name: 'search',
            data: {
                keyword: '创建',
            },
            // 返回操作后数据
            rawData: true
        })

        console.log('新增', data);

        data = await moss.findOne({
            name: 'search',
            where: {
                id: data.id
            },
        })

        console.log('查询单条', data);

        data = await moss.update({
            name: 'search',
            where: {
                id: data.id
            },
            data: {
                keyword: '修改后212312'
            },
            // 返回操作后数据
            rawData: true,
            debug: '123123',
        })

        console.log('修改结果', data);

        data = await moss.delete({
            name: 'search',
            where: {
                id: data.id
            },
        })

        console.log('删除', data);

    } catch (e) {
        console.log('e', e);
    }
})()